package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ScArea;
import com.ruoyi.business.service.IScAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 省市区Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/business/area")
public class ScAreaController extends BaseController
{
    @Autowired
    private IScAreaService scAreaService;

    /**
     * 查询省市区列表
     */
    @PreAuthorize("@ss.hasPermi('business:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScArea scArea)
    {
        startPage();
        List<ScArea> list = scAreaService.selectScAreaList(scArea);
        return getDataTable(list);
    }

    @GetMapping("/getAreaList")
    public AjaxResult getAreaList(ScArea scArea)
    {
        return AjaxResult.success(scAreaService.selectScAreaList(scArea));
    }

    /**
     * 导出省市区列表
     */
    @PreAuthorize("@ss.hasPermi('business:area:export')")
    @Log(title = "省市区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScArea scArea)
    {
        List<ScArea> list = scAreaService.selectScAreaList(scArea);
        ExcelUtil<ScArea> util = new ExcelUtil<ScArea>(ScArea.class);
        util.exportExcel(response, list, "省市区数据");
    }

    /**
     * 获取省市区详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scAreaService.selectScAreaById(id));
    }

    /**
     * 新增省市区
     */
    @PreAuthorize("@ss.hasPermi('business:area:add')")
    @Log(title = "省市区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScArea scArea)
    {
        return toAjax(scAreaService.insertScArea(scArea));
    }

    /**
     * 修改省市区
     */
    @PreAuthorize("@ss.hasPermi('business:area:edit')")
    @Log(title = "省市区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScArea scArea)
    {
        return toAjax(scAreaService.updateScArea(scArea));
    }

    /**
     * 删除省市区
     */
    @PreAuthorize("@ss.hasPermi('business:area:remove')")
    @Log(title = "省市区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scAreaService.deleteScAreaByIds(ids));
    }
}
